package com.c6906.vdam.das.model.entity;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.c6906.vdam.das.common.EWTypeEnum;
import com.c6906.vdam.das.common.SnowFlakeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;

@Data
@ApiModel(description = "监督管理_用车预警")
@TableName("ew_vehicles_warn")
public class EWVehiclesWarn implements Serializable {
    @TableId
    @ApiModelProperty(value = "预警id")
    private Long ewId;

    @ApiModelProperty(value = "预警ids")
    private String ewIds;

    @ApiModelProperty(value = "预警次数")
    private Integer ewSum;

    @ApiModelProperty(value = "组织层级编码")
    private String regionCode;

    @ApiModelProperty(value = "组织层级名称")
    private String regionName;

    @ApiModelProperty(value = "单位id")
    private Long unitId;

    @ApiModelProperty(value = "单位名称")
    private String unitName;

    @ApiModelProperty(value = "监管对象")
    private String supervise;

    @ApiModelProperty(value = "预警类型编码")
    private String ewTypeId;

    @ApiModelProperty(value = "预警类型名称")
    private String ewTypeName;

    @ApiModelProperty(value = "业务编码")
    private String objectCode;

    @ApiModelProperty(value = "预警内容，例如一函多餐、同城接待、…。")
    private String ewRemark;

    @ApiModelProperty(value = "处置状态，默认（0未处理1处置中2已处理）")
    private Integer treatment;

    @ApiModelProperty(value = "预警级别，字典表【预警级别】")
    private Integer warningLevel;

    @ApiModelProperty(value = "处置受理单位id")
    private Long dealUnitId;

    @ApiModelProperty(value = "处置受理单位名称")
    private String dealUnitName;

    @ApiModelProperty(value = "处置受理时间")
    private Timestamp dealTime;

    @ApiModelProperty(value = "流程实例id")
    private Long instanceId;

    @ApiModelProperty(value = "当前环节编码")
    private String nodeCode;

    @ApiModelProperty(value = "当前环节名称")
    private String nodeName;

    @ApiModelProperty(value = "创建人")
    private Long createUser;

    @ApiModelProperty(value = "创建人姓名")
    private String createUserName;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改人")
    private Long updateUser;

    @ApiModelProperty(value = "修改人姓名")
    private String updateUserName;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "状态")
    private Integer status;

    @ApiModelProperty(value = "默认0")
    private Integer isDeleted;

    @ApiModelProperty(value = "车辆编码")
    private Long vehiclesCode;

    @ApiModelProperty(value = "车牌号码")
    private String vehPlateNum;

    @ApiModelProperty(value = "车辆性质id")
    private String vehPropId;

    @ApiModelProperty(value = "车辆性质名称")
    private String vehPropName;

    @ApiModelProperty(value = "车辆类型id")
    private String vehTypeId;

    @ApiModelProperty(value = "车辆类型名称")
    private String vehTypeName;

    @ApiModelProperty(value = "车辆所属单位id")
    private Long ownUnitId;

    @ApiModelProperty(value = "车辆所属单位名称")
    private String ownUnitName;

    public EWVehiclesWarn(EWVehiclesNoTask ewVehiclesNoTask, TerminalBusinessInfo tbi) {
        this.ewId = SnowFlakeUtil.getFlowIdInstance().nextId();
        this.regionCode = tbi.getRegionCode();
        this.regionName = tbi.getRegionName();
        this.unitId = Long.parseLong(tbi.getUseUnitId());
        this.unitName = tbi.getUseUnitName();
        this.ewTypeId = EWTypeEnum.NO_TASK.getId();
        this.ewTypeName = EWTypeEnum.NO_TASK.getName();
        this.ewRemark = DateUtil.format(ewVehiclesNoTask.getStartTime(), DatePattern.NORM_DATETIME_MINUTE_FORMAT) + " 至 " + DateUtil.format(ewVehiclesNoTask.getEndTime(), DatePattern.NORM_DATETIME_MINUTE_FORMAT)
                + "，" + ewVehiclesNoTask.getDayType() + "无任务出车，" + "从" + ewVehiclesNoTask.getStartAddr() + "到" + ewVehiclesNoTask.getEndAddr() + "，" + (ewVehiclesNoTask.getDuration() / 60 == 0 ? "" : ewVehiclesNoTask.getDuration() / 60 + "小时")
                + ewVehiclesNoTask.getDuration() % 60 + "分钟，约" + String.format("%.1f", ewVehiclesNoTask.getMileage()) + "公里。";
        this.treatment = 0;
        this.warningLevel = 4;
        this.vehiclesCode = Long.parseLong(tbi.getVehiclesCode());
        this.vehPlateNum = tbi.getVehPlateNum();
        this.vehPropId = tbi.getVehPropId();
        this.vehPropName = tbi.getVehPropName();
        this.vehTypeId = tbi.getVehTypeId();
        this.vehTypeName = tbi.getVehTypeName();
        this.ownUnitId = Long.parseLong(tbi.getOwnUnitId());
        this.ownUnitName = tbi.getOwnUnitName();
        this.createUser = 100L;
        this.createUserName = "系统自动处理";
        this.createTime = DateUtil.date();
        this.status = 1;
        this.isDeleted = 0;
    }

    public EWVehiclesWarn(EWVehiclesIllegalParking ewVehiclesIllegalParking, TerminalBusinessInfo tbi) {
        this.ewId = SnowFlakeUtil.getFlowIdInstance().nextId();
        this.regionCode = tbi.getRegionCode();
        this.regionName = tbi.getRegionName();
        this.unitId = Long.parseLong(tbi.getUseUnitId());
        this.unitName = tbi.getUseUnitName();
        this.ewTypeId = EWTypeEnum.ILLEGAL_PARK.getId();
        this.ewTypeName = EWTypeEnum.ILLEGAL_PARK.getName();
        this.ewRemark = DateUtil.format(ewVehiclesIllegalParking.getStartTime(), DatePattern.NORM_DATETIME_MINUTE_FORMAT) + " 至 " + DateUtil.format(ewVehiclesIllegalParking.getEndTime(), DatePattern.NORM_DATETIME_MINUTE_FORMAT)
                + "，" + (ewVehiclesIllegalParking.getDuration() / 60 == 0 ? "" : ewVehiclesIllegalParking.getDuration() / 60 + "小时") + ewVehiclesIllegalParking.getDuration() % 60 + "分钟，" + "未停放在车辆使用或权属单位，距离约" + String.format("%.1f", ewVehiclesIllegalParking.getOffsetDistance()) + "公里。";
        this.treatment = 0;
        this.warningLevel = 4;
        this.vehiclesCode = Long.parseLong(tbi.getVehiclesCode());
        this.vehPlateNum = tbi.getVehPlateNum();
        this.vehPropId = tbi.getVehPropId();
        this.vehPropName = tbi.getVehPropName();
        this.vehTypeId = tbi.getVehTypeId();
        this.vehTypeName = tbi.getVehTypeName();
        this.ownUnitId = Long.parseLong(tbi.getOwnUnitId());
        this.ownUnitName = tbi.getOwnUnitName();
        this.createUser = 100L;
        this.createUserName = "系统自动处理";
        this.createTime = DateUtil.date();
        this.status = 1;
        this.isDeleted = 0;
    }

    public EWVehiclesWarn(EWVehiclesUnauthTask ewVehiclesUnauthTask, TerminalBusinessInfo tbi) {
        this.ewId = SnowFlakeUtil.getFlowIdInstance().nextId();
        this.regionCode = tbi.getRegionCode();
        this.regionName = tbi.getRegionName();
        this.unitId = Long.parseLong(tbi.getUseUnitId());
        this.unitName = tbi.getUseUnitName();
        this.ewTypeId = EWTypeEnum.UNAUTH_TASK.getId();
        this.ewTypeName = EWTypeEnum.UNAUTH_TASK.getName();
//        (ewVehiclesUnauthTask.getOdometerMiles().doubleValue() > ewVehiclesUnauthTask.getEvalMiles().doubleValue() ? "，偏离" + String.format("%.1f", ewVehiclesUnauthTask.getOdometerMiles().subtract(ewVehiclesUnauthTask.getEvalMiles())) + " 公里。" : "。")
//        this.ewRemark = (alarmNums >= 2 ? "单车当月预警3次及以上，本月第" + alarmNums + 1 + "次。" : "") + "目的地不符，计划到达" + ewVehiclesUnauthTask.getTargetEndAddr() + "，实际到达" + ewVehiclesUnauthTask.getRealEndAddr() + "。";
        this.ewRemark = "目的地不符，计划到达" + ewVehiclesUnauthTask.getTargetEndAddr() + "，实际到达" + ewVehiclesUnauthTask.getRealEndAddr() + "。";
        this.treatment = 0;
        this.objectCode = ewVehiclesUnauthTask.getUseCode();
        this.warningLevel = ewVehiclesUnauthTask.getWarningLevel();
        this.vehiclesCode = Long.parseLong(tbi.getVehiclesCode());
        this.vehPlateNum = tbi.getVehPlateNum();
        this.vehPropId = tbi.getVehPropId();
        this.vehPropName = tbi.getVehPropName();
        this.vehTypeId = tbi.getVehTypeId();
        this.vehTypeName = tbi.getVehTypeName();
        this.ownUnitId = Long.parseLong(tbi.getOwnUnitId());
        this.ownUnitName = tbi.getOwnUnitName();
        this.createUser = 100L;
        this.createUserName = "系统自动处理";
        this.createTime = DateUtil.date();
        this.status = 1;
        this.isDeleted = 0;
    }

    public EWVehiclesWarn(EWVehicleDetail ewVehicleDetail, TerminalBusinessInfo tbi) {
        this.ewId = SnowFlakeUtil.getFlowIdInstance().nextId();
        this.regionCode = tbi.getRegionCode();
        this.regionName = tbi.getRegionName();
        this.unitId = Long.parseLong(tbi.getUseUnitId());
        this.unitName = tbi.getUseUnitName();
        this.ewTypeId = EWTypeEnum.ILLEGAL_PLACE.getId();
        this.ewTypeName = EWTypeEnum.ILLEGAL_PLACE.getName();
        this.ewRemark = DateUtil.format(ewVehicleDetail.getStartTime(), DatePattern.NORM_DATETIME_MINUTE_FORMAT) + " 进入" + ewVehicleDetail.getAreaName() + (ewVehicleDetail.getEwRemark().contains("风景") ? "风景区，" : "，") + DateUtil.format(ewVehicleDetail.getEndTime(), DatePattern.NORM_DATETIME_MINUTE_FORMAT) + " 离开，停留" + (ewVehicleDetail.getDuration() / 60 == 0 ? "" : ewVehicleDetail.getDuration() / 60 + "小时") + ewVehicleDetail.getDuration() % 60 + "分钟。";
        this.treatment = 0;
        this.warningLevel = ewVehicleDetail.getWarningLevel();
        this.vehiclesCode = Long.parseLong(tbi.getVehiclesCode());
        this.vehPlateNum = tbi.getVehPlateNum();
        this.vehPropId = tbi.getVehPropId();
        this.vehPropName = tbi.getVehPropName();
        this.vehTypeId = tbi.getVehTypeId();
        this.vehTypeName = tbi.getVehTypeName();
        this.ownUnitId = Long.parseLong(tbi.getOwnUnitId());
        this.ownUnitName = tbi.getOwnUnitName();
        this.createUser = 100L;
        this.createUserName = "系统自动处理";
        this.createTime = DateUtil.date();
        this.status = 1;
        this.isDeleted = 0;
    }

    public EWVehiclesWarn(Date start, String ewIds, TerminalBusinessInfo tbi, String alarmNums, EWTypeEnum ewTypeEnum, String limit) {
        this.ewId = SnowFlakeUtil.getFlowIdInstance().nextId();
        this.ewIds = ewIds;
        this.ewSum = Integer.valueOf(alarmNums);
        this.regionCode = tbi.getRegionCode();
        this.regionName = tbi.getRegionName();
        this.unitId = Long.parseLong(tbi.getUseUnitId());
        this.unitName = tbi.getUseUnitName();
        this.ewTypeId = EWTypeEnum.WARN_SUM.getId();
        this.ewTypeName = EWTypeEnum.WARN_SUM.getName();
        // 2024年12月**车牌号出入特定场所预警？次
        this.ewRemark = DateUtil.year(start) + "年" + (DateUtil.month(start) + 1) + "月，" + tbi.getVehPlateNum() + ewTypeEnum.getName() + "预警" + alarmNums + "次。";
        this.treatment = 0;
        this.warningLevel = 3;
        this.vehiclesCode = Long.parseLong(tbi.getVehiclesCode());
        this.vehPlateNum = tbi.getVehPlateNum();
        this.vehPropId = tbi.getVehPropId();
        this.vehPropName = tbi.getVehPropName();
        this.vehTypeId = tbi.getVehTypeId();
        this.vehTypeName = tbi.getVehTypeName();
        this.ownUnitId = Long.parseLong(tbi.getOwnUnitId());
        this.ownUnitName = tbi.getOwnUnitName();
        this.createUser = 100L;
        this.createUserName = "系统自动处理";
        this.createTime = DateUtil.date();
        this.status = 1;
        this.isDeleted = 0;
    }
}